/* eslint valid-jsdoc: "off" */

'use strict';

const path = require('path');

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
    /**
     * built-in config
     * @type {Egg.EggAppConfig}
     **/
    const config = (exports = {});

    // use for cookie sign key, should change to your own and keep security
    config.keys = appInfo.name + '_1602802854655_8975';

    // add your middleware config here
    config.middleware = ['errorHandler', 'authorization'];

    // 文件存放目录
    config.rootPath = {
        questions: path.join(__dirname, '../questions_save'),
        answers: path.join(__dirname, '../answers_save'),
    };

    // add your user config here
    // http://localhost:7001/swagger-ui.html
    const userConfig = {
        // myAppName: 'egg',
        security: {
            csrf: false,
        },
        swaggerdoc: {
            // 要扫描的目录
            dirScanner: './app/controller',
            // 接口文档说明
            apiInfo: {
                title: '考试系统接口',
                description: '八维研修学院考试系统 api 接口测试文档',
                version: '1.0.0',
            },
            // 通信协议
            schemes: ['http', 'https'],
            consumes: ['application/json'],
            produces: ['application/json'],
            securityDefinitions: {
                jwt: {
                    type: 'apiKey',
                    in: 'header',
                    name: 'token',
                },
                // oauth2: {
                //   type: 'oauth2',
                //   tokenUrl: 'http://petstore.swagger.io/oauth/dialog',
                //   flow: 'password',
                //   scopes: {
                //     'write:access_token': 'write access_token',
                //     'read:access_token': 'read access_token',
                //   },
                // },
            },
            enableSecurity: true,
            // 根据 @router 生成路由
            routerMap: true,
            enable: true,
        },
        mysql: {
            client: {
                host: 'localhost',
                port: 3306,
                user: 'root',
                password: 'root',
                database: 'sx_exam',
                // debug: ["ComQueryPacket", "RowDataPacket"],
                debug: ['ComQueryPacket'],
            },
        },
        authorization: {
            whiteList: ['/login', '/swagger*'],
        },
    };

    return {
        ...config,
        ...userConfig,
    };
};
